﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace INTROSE
{
    public partial class Login : Form
    {
        SqlConnection con = new SqlConnection("Data Source = .\\SQLEXPRESS; Database = Introse; Integrated Security = True");
        string name, position;
        public Login()
        {
            InitializeComponent();
        }

        public MenuExecutive menuA;
        public MenuProductionStaff menuB;

        private void btnEnter_Click_1(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand command = new SqlCommand("Select * From users where uName = '" + txtUn.Text + "' AND psWord = '" + txtPw.Text + "'", con);
            SqlDataReader reader1 = command.ExecuteReader();
            if (reader1.HasRows)
            {
                reader1.Read();
                MessageBox.Show("Login Successful!");
                if (reader1.GetString(3) == "president" || reader1.GetString(3) == "vice-president" || reader1.GetString(3) == "secretary")
                {
                    this.Hide();
                    menuA = new MenuExecutive(reader1.GetString(4), reader1.GetString(3));
                    this.name = reader1.GetString(4);
                    this.position = reader1.GetString(3);
                    menuA.Show();
                }
                else if (reader1.GetString(3) == "factory worker")
                {
                    this.Hide();
                    menuB = new MenuProductionStaff(reader1.GetString(4), reader1.GetString(3));
                    this.name = reader1.GetString(4);
                    this.position = reader1.GetString(3);
                    menuB.Show();
                }
            }
            else
            {
                MessageBox.Show("Incorrect Username and/or Password");
                txtUn.Clear();
                txtPw.Clear();
            }
            con.Close();
        }

        private void Login_Load(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void linkLblPw_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Hide();
            PasswordRevcovery pw = new PasswordRevcovery(name, position);
            pw.Show();
        }

    }
}
